	test("1", "1", "1", "1", "3");
	//接单
	function test(ordersId, num, currentPageProcessed, currentPageUntreated, pageTotal){
		$.ajax({
		    type: 'POST',
		    url: "/FAFCode/OrderManagement",
		    data: {"ordersId":ordersId,"BusinessCenter":num,"currentPageProcessed":currentPageProcessed, "currentPageUntreated":currentPageUntreated,"pageTotal":pageTotal},
		    dataType: 'json',
		    beforeSend: function () {
		        load();
		    },
		    complete: function () {
		        disLoad();
		    },
		    success: function (data) {
		    	//清空id为now的tr控件
				$("#now").empty();
				//清空id为history的tr控件
				$("#history").empty();
				//获得当前页(已审批)
				var currentPageProcessed = data.pageProcessed;
				//获得当前页(未审批)
				var currentPageUntreated = data.pageUntreated;
				
			 $.each(data.ordersList,function(i,orders){
				 
					 if(orders.ordersState==1 || orders.ordersState==2 || orders.ordersState==3){
						var totalPrice = 0.0;
						
						$("#history").append(
								"<ul class='order_list_th w978 clearfix' id='history_top"+ i +"'>"+
								"<li class='col01'>" + orders.ordersTime + "</li>" +
								"<li class='col02'>订单号："+orders.ordersNumber+"</li>"+
								"</ul>"+
								"<table class='order_list_table w980'>"+
								"<tbody>"+
								"<tr id='history_content"+i+"'>"+
								"<td width='55%' id='history_food"+i+"'>"+
								"</td>"+
								"</tr>"+
								"</tbody>"+
								"</table>"
						)
						 
						 $.each(data.detailList,function(j,detail){
							
		    						if(detail.orderNumber==orders.ordersNumber){
		    							$.each(data.foodList,function(n,food){
		    								if(detail.foodId == food.foodId){
		    									$("#history_food"+i).append(
		    											"<ul class='order_goods_list clearfix'>"+
		    											"<li class='col01'><img src= " + "/FAFCode/" +
		    											food.foodPhoto + "></li>"+
		    											"<li class='col02'>"+food.foodName+
													"<em>"+food.foodPrice+"元/份</em></li>"+
													"<li class='col03'>"+detail.foodNumber+"</li>"+
													"<li class='col04'>"+
													detail.foodNumber*food.foodPrice+
													"元</li></ul>"
		    									)
		    									totalPrice += detail.foodNumber*food.foodPrice;
		    								}
		    							})
		    							
		    								
		    						}
		    						
		    					})
		    					if(orders.ordersState==1){
    								$("#history_content"+i).append(
	    									"<td width='15%'>"+totalPrice+"元</td>"+
	    									"<td width='15%'>已接单</td>"+
	    									"<td width='15%'><a href='/FAFCode/OrderManagement/OrdersDetail.html' class='oper_btn'>查看信息</a></td>"		
	    							)
    							}else if(orders.ordersState==2){
    								$("#history_content"+i).append(
	    									"<td width='15%'>"+totalPrice+"元</td>"+
	    									"<td width='15%'><font color='red'>已拒单</font></td>"+
	    									"<td width='15%'><a href='/FAFCode/OrderManagement/OrdersDetail.html' class='oper_btn'>查看信息</a></td>"		
	    							)
    							}else if(orders.ordersState==3){
    								$("#history_content"+i).append(
	    									"<td width='15%'>"+totalPrice+"元</td>"+
	    									"<td width='15%'>已签收</td>"+
	    									"<td width='15%'><a href='/FAFCode/OrderManagement/OrdersDetail.html' class='oper_btn'>查看信息</a></td>"		
	    							)
    							}
								
					}else if(orders.ordersState==0){
						var totalPrice = 0.0;
						$("#now").append(
								"<ul class='order_list_th w978 clearfix' id='history_top"+ i +"'>"+
								"<li class='col01'>" + orders.ordersTime + "</li>" +
								"<li class='col02'>订单号："+orders.ordersNumber+"</li>"+
								"<li class='col02 stress'><a class='col02 stress' href='javascript:;' onclick='test("
								+ orders.ordersId + ",3,"+data.pageProcessed.pageNo+","+data.pageUntreated.pageNo+","+pageTotal+")'>拒单</a></li>"+
								"</ul>"+
								"<table class='order_list_table w980'>"+
								"<tbody>"+
								"<tr id='now_content"+i+"'>"+
								"<td width='55%' id='now_food"+i+"'>"+
								"</td>"+
								"</tr>"+
								"</tbody>"+
								"</table>"
						)
						$.each(data.detailList,function(j,detail){
		    						if(detail.orderNumber==orders.ordersNumber){
		    							$.each(data.foodList,function(n,food){
		    								if(detail.foodId == food.foodId){
		    									$("#now_food"+i).append(
		    											"<ul class='order_goods_list clearfix'>"+
		    											"<li class='col01'><img src= " + "/FAFCode/" +
		    											food.foodPhoto + "></li>"+
		    											"<li class='col02'>"+food.foodName+
													"<em>"+food.foodPrice+"元/份</em></li>"+
													"<li class='col03'>"+detail.foodNumber+"</li>"+
													"<li class='col04'>"+
													detail.foodNumber*food.foodPrice+
													"元</li></ul>"
		    									)
		    									totalPrice += detail.foodNumber*food.foodPrice;
		    								}
		    								
		    								
		    							})
		    							
		    							
		    						}
		    						
		    					})
		    				$("#now_content"+i).append(
			    									"<td width='15%'>"+totalPrice+"元</td>"+
			    									"<td width='15%'>未接单</td>"+
			    									"<td width='15%'><button href='javascript:;' class='oper_btn' style='cursor:pointer;' id='receiveOrder' onclick='test("+ orders.ordersId + ",2,"+data.pageProcessed.pageNo+","+data.pageUntreated.pageNo+","+pageTotal+")'>接单</button></td>"
			    									
		    				)
					}
					 
				
				})
				$("#pageUntreated").empty();
			 	$("#pageProcessed").empty();
			 	$("#pageProcessed").append(
			 		"<a href='#' onclick='test(1,1,"+data.pageProcessed.prePage+","+data.pageUntreated.pageNo+","+pageTotal+")'>上一页</a>"		
			 	)
			 	$("#pageUntreated").append(
			 		"<a href='#' onclick='test(1,1,"+data.pageProcessed.pageNo+","+data.pageUntreated.prePage+","+pageTotal+")'>上一页</a>"		
			 	)
			 	if(data.pageProcessed.pageCount >= 5){
			 		if(data.pageProcessed.pageNo <= 4){
			 			for(var page = 1; page <= 5; page++){
							if(page == data.pageProcessed.pageNo){
								$("#pageProcessed").append(
										"<a href='#' class='active' onclick='test(1, 1, "+page+","+data.pageUntreated.pageNo+","+pageTotal+")'>"+ page +"</a>"
									)
							}else{
								$("#pageProcessed").append(
										"<a href='#' onclick='test(1, 1, "+page+","+data.pageUntreated.pageNo+","+pageTotal+")'>"+ page +"</a>"
									)
							}
						}
			 		}else{
			 			var startPageNum = data.pageProcessed.pageNo - 1;
			 			var endPageNum = startPageNum + 4;
			 			if(endPageNum <= data.pageProcessed.pageCount){
			 				for(var page = startPageNum; page <= endPageNum; page++){
								if(page == data.pageProcessed.pageNo){
									$("#pageProcessed").append(
											"<a href='#' class='active' onclick='test(1, 1, "+page+","+data.pageUntreated.pageNo+","+pageTotal+")'>"+ page +"</a>"
										)
								}else{
									$("#pageProcessed").append(
											"<a href='#' onclick='test(1, 1, "+page+","+data.pageUntreated.pageNo+","+pageTotal+")'>"+ page +"</a>"
										)
								}
							}
			 			}else{
			 				for(var page = data.pageProcessed.pageCount-4; page <= data.pageProcessed.pageCount; page++){
								if(page == data.pageProcessed.pageNo){
									$("#pageProcessed").append(
											"<a href='#' class='active' onclick='test(1, 1, "+page+","+data.pageUntreated.pageNo+","+pageTotal+")'>"+ page +"</a>"
										)
								}else{
									$("#pageProcessed").append(
											"<a href='#' onclick='test(1, 1, "+page+","+data.pageUntreated.pageNo+","+pageTotal+")'>"+ page +"</a>"
										)
								}
							}
			 			}
			 			
			 		}
			 	}else{
			 		for(var page = 1; page <= data.pageProcessed.pageCount; page++){
						if(page == data.pageProcessed.pageNo){
							$("#pageProcessed").append(
									"<a href='#' class='active' onclick='test(1, 1, "+page+","+data.pageUntreated.pageNo+","+pageTotal+")'>"+ page +"</a>"
								)
						}else{
							$("#pageProcessed").append(
									"<a href='#' onclick='test(1, 1, "+page+","+data.pageUntreated.pageNo+","+pageTotal+")'>"+ page +"</a>"
								)
						}
					}
			 	}
				
			 $("#pageProcessed").append(
					 "<a href='#' onclick='test(1,1,"+data.pageProcessed.nextPage+","+data.pageUntreated.pageNo+","+pageTotal+")'>下一页</a>"
					 )
			if(data.pageUntreated.pageCount >= 5){
				if(data.pageUntreated.pageNo <= 4){
					for(var page = 1; page <= 5; page++){
						if(page == data.pageUntreated.pageNo){
							$("#pageUntreated").append(
									"<a href='#' class='active' onclick='test(1, 1, "+data.pageProcessed.pageNo+","+page+","+pageTotal+")'>"+ page +"</a>"
								)
						}else{
							$("#pageUntreated").append(
									"<a href='#' onclick='test(1, 1, "+data.pageProcessed.pageNo+","+page+","+pageTotal+")'>"+ page +"</a>"
								)
						}
					}
				}else{
					var startPageNum = data.pageUntreated.pageNo - 1;
		 			var endPageNum = startPageNum + 4;
					if(endPageNum <= data.pageUntreated.pageCount){
						for(var page = startPageNum; page <= endPageNum; page++){
							if(page == data.pageUntreated.pageNo){
								$("#pageUntreated").append(
										"<a href='#' class='active' onclick='test(1, 1, "+data.pageProcessed.pageNo+","+page+","+pageTotal+")'>"+ page +"</a>"
									)
							}else{
								$("#pageUntreated").append(
										"<a href='#' onclick='test(1, 1, "+data.pageProcessed.pageNo+","+page+","+pageTotal+")'>"+ page +"</a>"
									)
							}
						}
					}else{
						for(var page = data.pageUntreated.pageCount-4; page <= data.pageUntreated.pageCount; page++){
							if(page == data.pageUntreated.pageNo){
								$("#pageUntreated").append(
										"<a href='#' class='active' onclick='test(1, 1, "+data.pageProcessed.pageNo+","+page+","+pageTotal+")'>"+ page +"</a>"
									)
							}else{
								$("#pageUntreated").append(
										"<a href='#' onclick='test(1, 1, "+data.pageProcessed.pageNo+","+page+","+pageTotal+")'>"+ page +"</a>"
									)
							}
						}
					}
					
				}
			}else{
				for(var page = 1; page <= data.pageUntreated.pageCount; page++){
					if(page == data.pageUntreated.pageNo){
						$("#pageUntreated").append(
								"<a href='#' class='active' onclick='test(1, 1, "+data.pageProcessed.pageNo+","+page+","+pageTotal+")'>"+ page +"</a>"
							)
					}else{
						$("#pageUntreated").append(
								"<a href='#' onclick='test(1, 1, "+data.pageProcessed.pageNo+","+page+","+pageTotal+")'>"+ page +"</a>"
							)
					}
				}
			}
			 	
			 
			 $("#pageUntreated").append(
					 "<a href='#' onclick='test(1,1,"+data.pageProcessed.pageNo+","+data.pageUntreated.nextPage+","+pageTotal+")'>下一页</a>"
			 )
		    },
		    //当返回数据不成功时的操作
			error : function() {
				alert("请先登录！！！");
				window.location.href='/FAFCode/OrderManagement/login.html';
			}
		});
	
	}
	//弹出加载层
	function load() {
	    $("<div class=\"datagrid-mask\"></div>").css({
	        display: "block",
	        width: "100%",
	        height: $(window).height()
	    }).appendTo("body");
	    $("<div class=\"datagrid-mask-msg\"></div>").html("加载中，请稍候。。。").appendTo("body").css({
	        display: "block",
	        left: ($(document.body).outerWidth(true) - 190) / 2,
	        top: ($(window).height() - 45) / 2
	    });
	}
	//取消加载层  
	function disLoad() {
	    $(".datagrid-mask").remove();
	    $(".datagrid-mask-msg").remove();
	}